[Resource] az bicep: Add snapshot and run subcommands#33398
Conversation
- `az bicep snapshot`: Wraps the Bicep CLI `snapshot` command (introduced in Bicep CLI 0.41.2) to capture or validate deployment snapshots from a .bicepparam file. Supports `--mode`, `--tenant-id`, `--subscription-id`, `--management-group-id`, `--location`, `--resource-group`, and `--deployment-name`. - `az bicep run`: Generic passthrough that forwards a quoted command string to the installed Bicep CLI, allowing use of CLI features that don't yet have a dedicated `az bicep` wrapper. - Uses `shlex.split(..., posix=False)` plus quote stripping so Windows paths with backslashes are preserved. - Adds unit tests (TestBicepSnapshot, TestBicepRun) and LiveScenarioTests (BicepSnapshotTest, BicepRunTest).
️✔️AzureCLI-FullTest
|
|
Hi @shenglol, |
|
| rule | cmd_name | rule_message | suggest_message |
|---|---|---|---|
| bicep run | cmd bicep run added |
||
| bicep snapshot | cmd bicep snapshot added |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds two new Bicep subcommands to the resource module: az bicep snapshot (wraps Bicep CLI's snapshot command, requires Bicep CLI v0.41.2+) and az bicep run (generic passthrough that forwards a quoted command string to the Bicep CLI, preserving Windows-style backslashes via shlex non-POSIX mode).
Changes:
- Implements
snapshot_bicep_fileandrun_bicep_cli_passthroughincustom.py, wired up viacommands.py,_params.py, and_help.py. - Adds unit tests covering argument forwarding, version-gating, quote handling, and empty-command validation.
- Adds
LiveScenarioTestclasses exercising the new commands end-to-end against the installed Bicep CLI.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| src/azure-cli/azure/cli/command_modules/resource/custom.py | Adds snapshot_bicep_file and run_bicep_cli_passthrough implementations. |
| src/azure-cli/azure/cli/command_modules/resource/commands.py | Registers the new snapshot and run commands under the bicep group. |
| src/azure-cli/azure/cli/command_modules/resource/_params.py | Declares arguments for the new commands. |
| src/azure-cli/azure/cli/command_modules/resource/_help.py | Adds help text and examples for bicep snapshot and bicep run. |
| src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource_bicep.py | Adds unit tests for the new custom functions. |
| src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py | Adds live scenario tests for bicep snapshot and bicep run. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| class BicepSnapshotTest(LiveScenarioTest): | ||
| def setup(self): | ||
| super().setup() | ||
| self.cmd('az bicep uninstall') |
| class BicepRunTest(LiveScenarioTest): | ||
| def setup(self): | ||
| super().setup() | ||
| self.cmd('az bicep uninstall') |
| curr_dir = os.path.dirname(os.path.realpath(__file__)) | ||
| params_file = os.path.join(curr_dir, 'sample_params.bicepparam').replace('\\', '\\\\') | ||
| snapshot_path = os.path.join(curr_dir, 'sample_params.snapshot.json') |
| def run_bicep_cli_passthrough(cmd, command_string): | ||
| import shlex | ||
|
|
||
| # Use non-POSIX mode so that backslashes in Windows paths are preserved. | ||
| # In non-POSIX mode, shlex retains the surrounding quotes on quoted tokens, | ||
| # so strip them so the values are passed through cleanly to the Bicep CLI. | ||
| args = [] | ||
| for token in shlex.split(command_string, posix=False): |
| else: | ||
| logger.error("az bicep snapshot could not be executed with the current version of Bicep CLI. Please upgrade Bicep CLI to v%s or later.", minimum_supported_version) |
| c.argument('mode', arg_type=get_enum_type(['Overwrite', 'Validate']), | ||
| help="The snapshot mode. 'Overwrite' (default) writes the snapshot file. 'Validate' compares the existing snapshot against the current template and fails if differences are detected.") | ||
| c.argument('tenant_id', options_list=['--tenant-id'], help="The Azure tenant ID to use when capturing the snapshot.") | ||
| c.argument('subscription_id', options_list=['--subscription-id'], help="The Azure subscription ID to use when capturing the snapshot.") |
| c.argument('location', options_list=['--location'], help="The Azure location to use when capturing the snapshot.") | ||
| c.argument('resource_group', options_list=['--resource-group'], help="The Azure resource group name to use when capturing the snapshot.") |
| def run_bicep_cli_passthrough(cmd, command_string): | ||
| import shlex |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
Related command
az bicep snapshotaz bicep runDescription
az bicep snapshot: Wraps the Bicep CLIsnapshotcommand (introduced in Bicep CLI 0.41.2) to capture or validate deployment snapshots from a .bicepparam file. Supports--mode,--tenant-id,--subscription-id,--management-group-id,--location,--resource-group, and--deployment-name.az bicep run: Generic passthrough that forwards a quoted command string to the installed Bicep CLI, allowing use of CLI features that don't yet have a dedicatedaz bicepwrapper.shlex.split(..., posix=False)plus quote stripping so Windows paths with backslashes are preserved.Closes Azure/bicep#19502.
Testing Guide
History Notes
az bicep snapshot: New command to wrap the Bicep CLIsnapshotcommand to capture or validate deployment snapshots from a .bicepparam file.az bicep run: New command that forwards a quoted command string to the Bicep CLI, allowing use of CLI features that don't yet have a dedicatedaz bicepwrapper.This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.